package net.jueb.frameworkDemo.orm.mongodb.springDataMongodb.xmlStyle;

import java.util.Arrays;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import net.jueb.frameworkDemo.orm.mongodb.springDataMongodb.Address;
import net.jueb.frameworkDemo.orm.mongodb.springDataMongodb.MyRepository;
import net.jueb.frameworkDemo.orm.mongodb.springDataMongodb.Person;

public class Test {

	public static void main(String[] args) {
		ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("classpath:/net/jueb/jseTest/db/mongodb/springDataMongodb/xmlStyle/spring.xml");
		System.err.println(Arrays.toString(context.getBeanDefinitionNames()));
		MyRepository<Person> repository = context.getBean(Center_Person_Dao.class);
		repository.dropCollection();
		repository.createCollection();
		Person person = new Person();
		Address address = new Address();
		address.setAddr("合肥");
		address.setPro("安徽");
		person.setAddress(address);
		person.setAge(20);
		person.setName("senssic");
		person.setId("1");
		repository.saveObject(person);
		System.out.println("1. " + repository.getAllObjects());
		person.setId("101");
		repository.saveObject(person);
		System.out.println("2. " + repository.getAllObjects());
		System.out.println("Tree with id 1" + repository.getObject("1"));
		repository.updateObject("1", "sen");
		System.out.println("3. " + repository.getAllObjects());
		repository.deleteObject("1");
		System.out.println("4. " + repository.getAllObjects());
		context.close();
	}
}
